<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/font-awesome.min.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/doc.min.css">
	<style>
	.tree li{
        list-style-type: none;
		cursor:pointer;
	}
	</style>
</head>
<body>
<div class="col-sm-12 col-sm-offset-0 col-md-12 col-md-offset-0 main">
		<ol class="breadcrumb">
		  <li><a href="#">首页</a></li>
		  <li><a href="#">预告登记</a></li>
		</ol>
		<div class="panel panel-default">
	      <div class="panel-heading">表单数据<div style="float:right;cursor:pointer;" data-toggle="modal" data-target="#myModal"><i class="glyphicon glyphicon-question-sign"></i></div></div>
		  	<div class="panel-body" id="body">
				<%@ include file="/houseRegister/ROOTWO.jsp" %>
		 	</div>
		</div>
      </div>
	<div class="modal fade" tabindex="-1" role="dialog" id="addModal">
	  <div class="modal-dialog" role="document">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title">新增预告登记</h4>
	      </div>
	      <div class="modal-body">
	      	<form role="form" id="addFrom">
	      		<input type="hidden" value="">
		        <div class="form-group" style="padding: 20px;">
					<label for="exampleInputPassword1" class="col-sm-4 control-label" style="text-align: center;">姓名：</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" name="advanceNotice_name" placeholder="请输入姓名">
				  	</div>
				</div>
				<div class="form-group" style="padding: 20px;">
					<label for="exampleInputPassword1" class="col-sm-4 control-label" style="text-align: center;">电话：</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" name="advanceNotice_phone" placeholder="请输入电话">
				  	</div>
				</div>
				<div class="form-group" style="padding: 20px;">
					<label for="exampleInputPassword1" class="col-sm-4 control-label" style="text-align: center;">身份证号：</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" name="advanceNotice_IDCard" placeholder="请输入身份证号">
				  	</div>
				</div>
			</form>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	        <button type="button" class="btn btn-primary" id="save">保存</button>
	      </div>
	    </div><!-- /.modal-content -->
	  </div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
    <script src="${pageContext.request.contextPath}/jquery/jquery-2.1.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.min.js"></script>
	<script src="${pageContext.request.contextPath}/script/docs.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/json2.js"></script>
	<script type="text/javascript">
		$(function(){
			getAdvanceNotice();
		});
		function getAdvanceNotice(){
			$("#inquire").click(function(){
				var house_id=$("#house_id").val();
				getData(house_id);
			});
		};
		function getData(house_id){
			$.ajax({
				url:"${pageContext.request.contextPath}/advanceNotice/selectAdvancenoticeByhId",
				type:"post",
				async:true,
				data:{"house_id":house_id},
				error:function(){

				},
				success:function(data){
					var jsonData=null;
					var divStr="<div>";
					divStr=divStr+"<div style='float: right;padding-bottom: 10px;'><input type='button' value='新增' class='btn btn-primary' data-toggle='modal' data-target='#addModal'></div>";
					divStr=divStr+"<table class='table table-bordered' style='text-align: center;'>";
					divStr=divStr+"<tr>";
					divStr=divStr+"<td>预告编号</td>";
					if(data==''){
						divStr=divStr+"<td><input id='advanceNotice_id' type='text' placeholder='没有记录' style='text-align: center;'/></td>";
					}else{
						jsonData=JSON.parse(data);
						divStr=divStr+"<td><input id='advanceNotice_id' type='text' value='"+jsonData.advanceNotice_id+"' style='text-align: center;' readonly/></td>";
					}
					divStr=divStr+"<td>房屋编号</td>";
					divStr=divStr+"<td><input id='houseId' type='text' value='"+house_id+"' style='text-align: center;'/></td>";
					divStr=divStr+"</tr>";
					divStr=divStr+"<tr><td>姓名</td><td>电话号</td><td>身份证</td><td>操作</td></tr>";
					if(data!=''){
						var adName=jsonData.advanceNotice_name;
						var adID=jsonData.advanceNotice_IDCard;
						var adPhone=jsonData.advanceNotice_phone;
						var adNames=adName.split(",");
						var adIDs=adID.split(",");
						var adPhones=adPhone.split(",");
						for(var i=0;i<adIDs.length;i++){
							divStr=divStr+"<tr><td>"+adNames[i]+"</td>";
							divStr=divStr+"<td>"+adPhones[i]+"</td>";
							divStr=divStr+"<td>"+adIDs[i]+"</td>";
							divStr=divStr+"<td><input type='button' value='修改' class='btn btn-primary' name='update'/>";
							divStr=divStr+"<input type='button' value='删除' class='btn btn-danger' name='del'/></td>";
							divStr=divStr+"<tr>";
						}
					}
					divStr=divStr+"</table>";
					$("#body").html(divStr);
					addAdvanceNotice();
					delAdvanceNotice();
					updateAdvanceNotice();
				}
			});
		};
		function addAdvanceNotice(){
			var advanceNotice_id=$("#advanceNotice_id").val();
			var houseId=$("#houseId").val();
			$("#save").click(function(){
				$.ajax({
					url:"${pageContext.request.contextPath}/advanceNotice/addAdvancenotice",
					type:"post",
					async:true,
					data:$("#addFrom").serialize()+'&'+$.param({"advanceNotice_id":advanceNotice_id,"h_id":houseId}),
					error:function(){
						
					},
					success:function(data){
						alert(data);
						$('#addModal').modal('hide');
						$('#addModal').on('hidden.bs.modal', function (e) {});
						getData(houseId);
					}
				});
			});
			
		};
		function delAdvanceNotice(){
			$("[name=del]").click(function(){
				var adTag=$(this).parent().prevAll();
				var adName=$(adTag[2]).text();
				var adID=$(adTag[0]).text();
				var adPhone=$(adTag[1]).text();
				var hId=$("#houseId").val();
				$.ajax({
					url:"${pageContext.request.contextPath}/advanceNotice/delAdvancenotice",
					type:"post",
					async:true,
					data:{"adName":adName,"adID":adID,"adPhone":adPhone,"hId":hId},
					error:function(){
						
					},
					success:function(data){
						alert(data);
						getData(hId);
					}
				});
			});
		};
		
	</script>
</body>
</html>